package com.topscore.uke.mvp.model;

import com.topscore.uke.entities.UserInfo;
import com.topscore.uke.mvp.contractors.LoginContractor;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.network.request.LoginBean;
import com.topscore.uke.network.retrofit.ApiService;
import com.topscore.uke.network.retrofit.HandleErrorSubscriber;
import com.topscore.uke.network.retrofit.NetClientPostJson;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 71468 on 2017/9/13.
 */

public class LoginModel implements LoginContractor.Model,LoginContractor {
    private LoginListener listener;

    public LoginModel(LoginListener listener){
        this.listener = listener;
    }
    @Override
    public void login(LoginBean body) {
        mService.login(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<UserInfo>>(listener) {
                    @Override
                    public void onSuccess(BaseResponse<UserInfo> response) {
                        listener.onLoginSuccess(response);
                    }
                });

    }
}
